package com.mjk.common.tools.gson.adapter.impl;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.mjk.common.tools.logger.BizLogger;
import com.mjk.common.util.ClobUtils;

import javax.sql.rowset.serial.SerialClob;
import java.io.IOException;
import java.sql.Clob;

public class ClobAdapterImpl extends TypeAdapter<Clob> {


	@Override
	public void write(JsonWriter out, Clob value) throws IOException {
		out.value(ClobUtils.clobToString(value));
	}

	@Override
	public Clob read(JsonReader in) {
		try {
			return new SerialClob(in.nextString().toCharArray());
		} catch (Exception e) {
			BizLogger.error(e);
		}
		return null;
	}

}
